﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using RemotingInterfaces;

using Model.Adventure;
using Model.Hero;

namespace Model.Spells
{
    public class Spell : ISpell
    {
        private String _name; //name of the spell
        private bool _memorized; //is the spell memorized
        private double _intensity; //a measure of force upon impact for offensive spells
        //private int _rank; //higher rank spells are more powerfull
        private int _duration; //0 duration spells are instantenous, ex. fireball
        private int _min_required_int; //the minimum required intellect to learn this spell
        private IDamage _damage; //what types of damage does the spell do
        private IBuff _buff; //buff provided by the spell
        private IDebuff _debuff; //if the spell sustains a debuff on its target(s)
        private int _targets_affected; //maximum number of targets affected, 0 for infinity
        private int _healing_power; //how much the spell heals each target
        private double _spell_research_cost;

        public Spell() { }

        //non-damage based spells (
        public Spell(String name, double intensity, int duration, int min_int, IDamage dam, IBuff buff, IDebuff debuff, int targets_affected, int healing_power)
        {
            _name = name;
            //_rank = rank;
            _intensity = intensity;
            _duration = duration;
            _min_required_int = min_int;
            _damage = dam;
            _buff = buff;
            _debuff = debuff;
            _targets_affected = targets_affected;
            _healing_power = healing_power;
        }

        public String Name
        {
            get { return _name; }
            set
            {
                _name = value;
            }
        }

        public bool Memorized
        {
            get { return _memorized; }
            set
            {
                _memorized = value;
            }
        }

        public double Intensity
        {
            get { return _intensity; }
            set
            {
                _intensity = value;
            }
        }

        /*
        public int Rank
        {
            get { return _rank; }
            set
            {
                _rank = value;
            }
        }
        */

        public int Duration
        {
            get { return _duration; }
            set
            {
                _duration = value;
            }
        }

        public int Minimum_Required_Intellect
        {
            get { return _min_required_int; }
            set
            {
                _min_required_int = value;
            }
        }
        
        public IDamage Damage_Stats
        {
            get { return _damage; }
        }

        public IBuff Buff
        {
            get { return _buff; }
        }

        public IDebuff Debuff
        {
            get { return _debuff; }
        }

        public int Targets_Affected
        {
            get { return _targets_affected; }
            set
            {
                _targets_affected = value;
            }
        }

        public double Spell_Power
        {
            get
            {
                //should be based on damage, duration, intensity and targets affected for damage spells
                //refine these calculations
                if (_damage != null)
                {                    
                    return _damage.Base_Damage * (_duration > 0 ? _duration : 1) * _intensity * _targets_affected;
                }
                else
                    return Healing_Power * (_duration > 0 ? _duration : 1) * _intensity * _targets_affected;

                return 0; 
            }
        }

        public int Healing_Power
        {
            get { return _healing_power; }
            set
            {
                _healing_power = value;
            }
        }

        public double Spell_Research_Cost
        {
            get { return _spell_research_cost; }
            set
            {
                _spell_research_cost = value;
            }
        }

        public static bool operator < (Spell spell1, Spell spell2)
        {
            return spell1.Spell_Power < spell2.Spell_Power;
        }

        public static bool operator > (Spell spell1, Spell spell2)
        {
            //swapping operands
            return spell2 < spell1;
        }

        public override string ToString()
        {
            String str = "";
            str += "Name: " + _name + "\n";
                //"Rank: " + _rank + "\n";
            return str;
        }
    }
}
